package com.ourway.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.ourway.dtos.DepartmentDTO;
import lombok.Data;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.util.Date;


/**
 * 部门
 *
 * @author lwh
 * @date 2021/11/28
 */
@TableName("department")
@Data
@Accessors(chain = true)
public class Department implements Serializable {

    /**
     * 自增长ID
     */
    @TableId(value = "id", type = IdType.AUTO)
    private int id;

    /**
     * 部门ID，唯一标识
     */
    private String departmentId;

    /**
     * 父部门ID
     */
    private String parentId;

    /**
     * 名称
     */
    private String name;

    /**
     * 创建时间
     */
    private Date createTime;

    /**
     * 更新时间
     */
    private Date updateTime;

    /**
     * 删除标识
     */
    private Integer deleteFlag;

    public static Department dtoToEntity(DepartmentDTO dto) {
        Department department = new Department()
                .setName(dto.getName())
                .setDepartmentId(dto.getDepartmentId())
                .setParentId(dto.getParentId())
                .setCreateTime(dto.getCreateTime())
                .setUpdateTime(dto.getUpdateTime());
        if (null != dto.getId()) {
            department.setId(dto.getId());
        }
        return department;
    }

}
